import sk_math

class Event(object):
	def __init__(self):
		pass
		

class ConsoleMsg(Event):
	def __init__(self,message):
		self.message = message


#-----------------------------------------------------------------------		
class CriminalAction(Event):
	def __init__(self, x, y, criminal):
		self.criminal = criminal
		self.origin = sk_math.Point(x,y)
#-----------------------------------------------------------------------		
class MurderEvent(CriminalAction):
	def __init__(self, x, y, criminal, victim):
		super(MurderEvent,self).__init__(x, y, criminal)
		self.victim = victim
#-----------------------------------------------------------------------		
class NPCReportCrimeEvent(Event):
	def __init__(self, x, y):
		self.origin = sk_math.Point(x,y)
		#self.entity = entity		
		
class NPCWitnessCrimeEvent(Event):
	def __init__(self, x, y):
		self.origin = sk_math.Point(x,y)
#-------------------------entity events---------------------------------		
class EntSpawnEvent(Event):
	def __init__(self, x, y, entity):
		self.spawn = sk_math.Point(x,y)	#todo: change to origin
		self.entity = entity
		
class EntDestroyEvent(Event):
	def __init__(self, entity):
		self.entity = entity
		
class EntDieEvent(Event):
	def __init__(self, entity):
		self.entity = entity

class EntMoveEvent(Event):
	def __init__(self, from_x, from_y, to_x, to_y, entity):
		self._from = sk_math.Point(from_x,from_y)
		self._to = sk_math.Point(to_x,to_y)
		self.entity = entity
#--------------------------player events--------------------------------
class PlayerOpenContainer(Event):
	def __init__(self, entity):
		self.entity = entity
	
#-----------------------------------------------------------------------
'''
When posted, every pedestrian in suspicious sound radius should locate sound source and treat it as crimeplace
i.e. post message "One of the neighbours reported suspicious activity to the police"
'''
class SoundEvent(Event):
	def __init__(self, x, y, radius, source = None):
		self.origin = sk_math.Point(x,y)
		self.radius = radius
		self.source = source
		
class SuspiciousSoundEvent(SoundEvent):
	def __init__(self, x, y, radius, source = None):
		super(SuspiciousSoundEvent,self).__init__(x, y, radius, source)


class EventListener(object):
	def __init__(self):
		self.em = None
		
	def notify(self,event):
		pass
		
	def set_em(self,em):
		self.em = em

class EventManager(object):
	def __init__(self,con,map,viewport):
		self.map = map
		self.con = con
		self.viewport = viewport
		
		self.services = {}
		
	def register(self,name,obj):
		#print "registering service '" + name + "'"
		
		self.services[name] = obj
		#FIXME!!!
		
		if hasattr(obj,"em"):
			obj.set_em(self)
			
		if hasattr(obj,"register"):
			obj.register(self)

	def post(self,event):		
		for (srvc_name, service) in self.services.iteritems():
			#print "posting event for service " + service.__class__.__name__
			
			if hasattr(service,"notify"):
				service.notify(event)

